package mylab.utils.common.guava;

import cn.hutool.core.thread.ThreadUtil;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;

import java.util.concurrent.ExecutorService;


public class AsyncEventUtil {

    @SuppressWarnings("UnstableApiUsage")
    private static EventBus bus;

    static {
        ExecutorService executor = ThreadUtil.newExecutor();

        bus = new AsyncEventBus("asyncBus", executor);
        bus.register(new DeadEventListener());
    }

    public static void regist(Object listener) {
        bus.register(listener);
    }

    public static void unregist(Object listener) {
        bus.unregister(listener);
    }

    public static void postEvent(Object event) {
        bus.post(event);
    }
}
